<?php
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/fileuploader/fileuploader.js', CClientScript::POS_HEAD);
Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl . '/js/fileuploader/fileuploader.css');
Yii::app()->clientScript->registerScript('tabs', '
    $( "#tabs" ).tabs();
    ');
?>
<div class="flexform" id="tabs">
    <?php
    $form = $this->beginWidget('CActiveForm', array(
        'id' => 'web-option-form',
        'enableAjaxValidation' => false,
            ));
    ?>

    <?php //echo $form->errorSummary($model); ?>
    <ul>
        <li><a href="#tabs-1">基本信息</a></li>
        <li><a href="#tabs-2">SEO</a></li>
        <li><a href="#tabs-3">支付设置</a></li>
        <li><a href="#tabs-4">客服信息</a></li>
        <li><a href="#tabs-5">社交帐号</a></li>
    </ul>

    <div id="tabs-1">
        <div class="row">
            <?php echo $form->labelEx($model, 'site_name'); ?>
            <?php echo $form->textField($model, 'site_name', array('size' => 60, 'maxlength' => 255)); ?>
            <?php echo $form->error($model, 'site_name', array('class' => 'form-msg-error-advanced')); ?>
        </div>

        <div class="row">
            <?php echo $form->labelEx($model, 'site_description'); ?>
            <?php echo $form->textField($model, 'site_description', array('size' => 60, 'maxlength' => 255)); ?>
            <?php echo $form->error($model, 'site_description', array('class' => 'form-msg-error-advanced')); ?>
        </div>

        <div class="row">
            <?php echo $form->labelEx($model, 'site_url'); ?>
            <?php echo $form->textField($model, 'site_url', array('size' => 60, 'maxlength' => 255)); ?>
            <?php echo $form->error($model, 'site_url', array('class' => 'form-msg-error-advanced')); ?>
        </div>

        <div class="row">
            <?php echo $form->labelEx($model, 'site_mail'); ?>
            <?php echo $form->textField($model, 'site_mail', array('size' => 60, 'maxlength' => 255)); ?>
            <?php echo $form->error($model, 'site_mail', array('class' => 'form-msg-error-advanced')); ?>
        </div>

        <div class="row">
            <?php echo $form->labelEx($model, 'site_logo'); ?>
            <?php echo $form->textField($model, 'site_logo', array('size' => 60, 'maxlength' => 255)); ?>
            <?php echo $form->error($model, 'site_logo', array('class' => 'form-msg-error-advanced')); ?>
            <div id="upload-file">
                <noscript>          
                <p>Please enable JavaScript to use file uploader.</p>
                </noscript>   
            </div>
        </div>

        <div class="row">
            <?php echo $form->labelEx($model, 'order_prefix'); ?>
            <?php echo $form->textField($model, 'order_prefix', array('size' => 20, 'maxlength' => 20)); ?>
            <?php echo $form->error($model, 'order_prefix', array('class' => 'form-msg-error-advanced')); ?>
        </div>
        <div class="clear"></div>
    </div>

    <div id="tabs-2">

        <div class="row">
            <?php echo $form->labelEx($model, 'seo_title'); ?>
            <?php echo $form->textField($model, 'seo_title', array('size' => 60, 'maxlength' => 255)); ?>
            <?php echo $form->error($model, 'seo_title', array('class' => 'form-msg-error-advanced')); ?>
        </div>

        <div class="row">
            <?php echo $form->labelEx($model, 'seo_keyword'); ?>
            <?php echo $form->textField($model, 'seo_keyword', array('size' => 60, 'maxlength' => 255)); ?>
            <?php echo $form->error($model, 'seo_keyword', array('class' => 'form-msg-error-advanced')); ?>
        </div>

        <div class="row">
            <?php echo $form->labelEx($model, 'seo_description'); ?>
            <?php echo $form->textArea($model, 'seo_description', array('cols' => 62, 'rows' => 3)); ?>
            <?php echo $form->error($model, 'seo_description', array('class' => 'form-msg-error-advanced')); ?>
        </div>
        <div class="clear"></div>
    </div>

    <div id="tabs-3">
        <div class="row">
            <?php echo $form->labelEx($model, 'payment_paypal'); ?>
            <?php echo $form->textField($model, 'payment_paypal', array('size' => 60, 'maxlength' => 255)); ?>
            <?php echo $form->error($model, 'payment_paypal', array('class' => 'form-msg-error-advanced')); ?>
        </div>

        <div class="row">
            <?php echo $form->labelEx($model, 'payment_western_union'); ?>
            <div style="padding-left: 130px;width: 60%;">
                <?php
                $this->widget('application.extensions.ckeditor.CKEditor', array(
                    "model" => $model, # Data-Model
                    "attribute" => 'payment_western_union', # Attribute in the Data-Model
                    "width" => '60%',
                ));
                ?>
            </div>
            <?php echo $form->error($model, 'payment_western_union', array('class' => 'form-msg-error-advanced')); ?>
        </div>
        <div class="clear"></div>
    </div>


    <div id="tabs-4">
        <div class="row">
            <?php echo $form->labelEx($model, 'service_phone'); ?>
            <?php echo $form->textField($model, 'service_phone', array('size' => 60, 'maxlength' => 255)); ?>
            <?php echo $form->error($model, 'service_phone', array('class' => 'form-msg-error-advanced')); ?>
        </div>

        <div class="row">
            <?php echo $form->labelEx($model, 'service_mail'); ?>
            <?php echo $form->textField($model, 'service_mail', array('size' => 60, 'maxlength' => 255)); ?>
            <?php echo $form->error($model, 'service_mail', array('class' => 'form-msg-error-advanced')); ?>
        </div>

        <div class="row">
            <?php echo $form->labelEx($model, 'service_livechat'); ?>

            <div style="padding-left: 130px;width: 60%;">
                <?php
                $this->widget('application.extensions.ckeditor.CKEditor', array(
                    "model" => $model, # Data-Model
                    "attribute" => 'service_livechat', # Attribute in the Data-Model
                    "width" => '60%',
                ));
                ?>
            </div>
            <?php echo $form->error($model, 'service_livechat', array('class' => 'form-msg-error-advanced')); ?>
        </div>
        
        <div class="clear"></div>
    </div>
    
    <div id="tabs-5">
        <div class="row">
            <?php echo $form->labelEx($model, 'sns_facebook'); ?>
            <?php echo $form->textField($model, 'sns_facebook', array('size' => 60, 'maxlength' => 255)); ?>
            <?php echo $form->error($model, 'sns_facebook', array('class' => 'form-msg-error-advanced')); ?>
        </div>
        <div class="row">
            <?php echo $form->labelEx($model, 'sns_youtube'); ?>
            <?php echo $form->textField($model, 'sns_youtube', array('size' => 60, 'maxlength' => 255)); ?>
            <?php echo $form->error($model, 'sns_youtube', array('class' => 'form-msg-error-advanced')); ?>
        </div>
        <div class="row">
            <?php echo $form->labelEx($model, 'sns_twitter'); ?>
            <?php echo $form->textField($model, 'sns_twitter', array('size' => 60, 'maxlength' => 255)); ?>
            <?php echo $form->error($model, 'sns_twitter', array('class' => 'form-msg-error-advanced')); ?>
        </div>
        <div class="row">
            <?php echo $form->labelEx($model, 'sns_google'); ?>
            <?php echo $form->textField($model, 'sns_google', array('size' => 60, 'maxlength' => 255)); ?>
            <?php echo $form->error($model, 'sns_google', array('class' => 'form-msg-error-advanced')); ?>
        </div>
        <div class="clear"></div>
    </div>

    <div class="action">
        <?php echo CHtml::submitButton($model->isNewRecord ? '提 交' : '修 改'); ?>
    </div>
    <div class="clear"></div>

    <?php $this->endWidget(); ?>

</div>
<!-- form -->

<div class="clear"></div>

<script>
    //file upload
    var upimg='';
    var img_ext = "|jpg|jpeg|png|gif|bmp|";
    function createUploader(elementObj, setValueObj){//   elementObj: DIV, setValueObj: Will set value INPUT    
        var uploader = new qq.FileUploader({
            element: elementObj,
            action: '<?php echo Yii::app()->baseUrl; ?>/fileUpload.php',
            debug: false,
            showMessage: function(message){ alert(message); },
            allowedExtensions: ['jpg', 'jpeg', 'png', 'gif', 'bmp'],
            onProgress: function(id, fileName, loaded, total){
                //location.reload();
            },
            onComplete:function(id, fileName, responseJSON){
                if(responseJSON.success){
                    var dot_index = responseJSON.url.lastIndexOf('.');
                    var ext = responseJSON.url.substring(dot_index+1);
                    if(img_ext.indexOf(ext)>0){
                        //setValueObj.value=responseJSON.url;
                        setValueObj.val(responseJSON.url.replace('uploads/..', ''));
                    }
                }
            }
        });
        uploader.setParams({dir:"../images"});
    }
    $(window).load(function(){
        createUploader(document.getElementById("upload-file"), $("#WebOption_site_logo"));
    });

</script>